﻿#region namespaces

using System;

#endregion

namespace ZOIL.DataBackend.BaseX
{
    public sealed partial class Database
    {
        #region IDatabase Members

        /// <summary>
        ///     Raised whenever a new object was created remotely and was accepted on this client via the
        ///     <see
        ///         cref="DatabaseConfiguration.AcceptRemotelyCreatedObjectCondition" />
        ///     function
        /// </summary>
        public event EventHandler<DatabaseObjectActionEventArgs> ObjectRemotelyCreated;

        /// <summary>
        ///     Raised whenever a local existing object was deleted remotely
        /// </summary>
        public event EventHandler<DatabaseObjectActionEventArgs> ObjectRemotelyDeleted;

        #endregion

        private void OnObjectRemotelyCreated(DatabaseObjectActionEventArgs e)
        {
            EventHandler<DatabaseObjectActionEventArgs> handler = ObjectRemotelyCreated;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        private void OnObjectRemotelyDeleted(DatabaseObjectActionEventArgs e)
        {
            EventHandler<DatabaseObjectActionEventArgs> handler = ObjectRemotelyDeleted;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        public event EventHandler<DatabaseObjectActionEventArgs> ObjectRemotelyUpdated;

        public void OnObjectRemotelyUpdated(DatabaseObjectActionEventArgs e)
        {
            EventHandler<DatabaseObjectActionEventArgs> handler = ObjectRemotelyUpdated;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        public event EventHandler<DatabaseObjectActionEventArgs> ObjectRemotelyMoved;

        public void OnObjectRemotelyMoved(DatabaseObjectActionEventArgs e)
        {
            EventHandler<DatabaseObjectActionEventArgs> handler = ObjectRemotelyMoved;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        public event EventHandler<MessageReceivedEventArgs> MessageReceived;

        private void OnMessageReceived(string message)
        {
            EventHandler<MessageReceivedEventArgs> handler = MessageReceived;
            if (handler != null)
            {
                handler(this, new MessageReceivedEventArgs(message));
            }
        }
    }
}